﻿using System.Collections.Generic;
using System.Linq;
using DyUi.Interfaces;

namespace DyUi.Core.Controls
{
    public class Layout : DyUiControl
    {
        IList<Region> _regions;

        public override void Prepare()
        {
            base.Prepare();

            _regions = Enumerable.ToList<Region>(this.FindLogicalChildren<Region>());

            foreach (var region in _regions)
            {
                var regionContent = FactoryService.CreateDyUiControl(region.DyUiName);

                if (regionContent != null)
                {
                    regionContent.Prepare();
                    region.Content = regionContent;
                }
            }
        }
    }
}
